package com.suitsoft.bdms.web.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.suitsoft.bdms.commos.LogAnnotation;
import com.suitsoft.bdms.entity.system.SystemCategory;
import com.suitsoft.bdms.entity.system.SystemInfo;
import com.suitsoft.bdms.service.system.SystemCategoryManager;
import com.suitsoft.bdms.service.system.SystemInfoManager;
import com.suitsoft.bdms.web.CrudActionSupport;

/** 
 * 系统参数
 *@author Suineg
 */
@Results({@Result(name=CrudActionSupport.RELOAD,location="system.action",type="redirect")})
public class SystemAction extends CrudActionSupport<SystemInfo>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private SystemInfoManager systemInfoManager;
	private SystemCategoryManager categoryManager;
	
	private SystemInfo systemInfo;
	private Long id;
	private List<SystemInfo> systemList;
	private List<SystemCategory> categories;
	
	

	@Override
	public String delete() throws Exception {
		if(id == null || id == 0l){
			addActionMessage("非法操作！");
			return list();
		}
		systemInfoManager.delete(id);
		return RELOAD;
	}

	@Override
	public String input() throws Exception {
		categories = categoryManager.getAll();
		return INPUT;
	}

	@Override
	public String list() throws Exception {
		systemList = systemInfoManager.getAll();
		return SUCCESS;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			systemInfo = systemInfoManager.get(id);
		}else{
			systemInfo = new SystemInfo();
		}
		
	}

	@Override
	@LogAnnotation(log = "系统参数管理 - 保存")
	public String save() throws Exception {
		systemInfoManager.save(systemInfo);
		addActionMessage("保存成功！");
		return RELOAD;
	}

	@Override
	public SystemInfo getModel() {
		return systemInfo;
	}
	@Autowired
	public void setSystemInfoManager(SystemInfoManager systemInfoManager) {
		this.systemInfoManager = systemInfoManager;
	}

	public List<SystemInfo> getSystemList() {
		return systemList;
	}

	public void setSystemList(List<SystemInfo> systemList) {
		this.systemList = systemList;
	}
	public SystemInfo getSystemInfo() {
		return systemInfo;
	}
	public void setSystemInfo(SystemInfo systemInfo) {
		this.systemInfo = systemInfo;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}

	public List<SystemCategory> getCategories() {
		return categories;
	}

	public void setCategories(List<SystemCategory> categories) {
		this.categories = categories;
	}
	@Autowired
	public void setCategoryManager(SystemCategoryManager categoryManager) {
		this.categoryManager = categoryManager;
	}
	
}

